import { message } from "antd";
import axios from "axios";

export const request = axios.create({
  baseURL: import.meta.env.VITE_API,
  timeout: 100000000,
});

request.interceptors.request.use((config) => {
  const token = localStorage.getItem("token");
  if (token) {
    config.headers["Authorization"] = `Bearer ${token}`;
  }
  return config;
});

request.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
    if (error?.response?.data?.message) {
      message.error(error.response.data.message);
    }
    Promise.reject(error);
  }
);
